import { Component } from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';
import { HttpClient } from '@angular/common/http';
import { HttpService } from '../../../service/httpService';
import { CookieService } from 'ngx-cookie-service';
@Component({
  selector: 'page-bank',
  templateUrl: 'addBank.html',
})
export class AddBankPage {

  private banksColumns = [];
  private addressColumns = [];
  private banks:any;

  constructor(public navCtrl: NavController,
              public httpClient: HttpClient,
              public http:HttpService,
              public cookie:CookieService,
              public navParams: NavParams) {
    this.initData();
  }

  initData(){
    let self = this;

    this.httpClient.get('./assets/citys.json',{}).subscribe( res => {
      let obj:any = res;
      var province = {name:'province', options:[]};
      var city = {name:'city', parentCol:'province', options:[]};
      var cityIndex = 0;
      for(var i=0;i< obj.length;i++){
        province.options.push({text:obj[i].name,value:i+""});
        for(var j=0;j<obj[i].city.length;j++){
          city.options.push({text:obj[i].city[j].name,value:cityIndex+"",parentVal:i+""});
          cityIndex++;
        }
      }
      this.addressColumns = [province, city];
    });

    this.http.get('/api/Config/GetBankList',{},function (res,err) {
      if (!err){
        self.banks = res;
        let banks = [];
        for(var i=0;i<res.length;i++){
          banks.push({text:res[i].BankName,value:res[i].Id+""});
        }
        self.banksColumns = [{name: 'col1', options: banks}];
        console.log(self.banksColumns);
      }
    });
  }

  addBankAction(){
    console.log('添加银行卡');
  }
}
